unit untConsultaDAPPec;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, untConsultaPadrao, ACBrBase, ACBrEnterTab, dxmdaset, dxBarDBNav,
  dxBar, cxClasses, DB, IBCustomDataSet, ActnList, cxPropertiesStore,
  cxContainer, cxEdit, cxStyles, cxGridTableView, cxLookAndFeels,
  cxGridCustomPopupMenu, cxGridPopupMenu, ImgList, cxGraphics, ExtCtrls,
  cxPC, cxControls, cxCustomData, cxFilter, cxData, cxDataStorage,
  cxDBData, cxCurrencyEdit, cxGridLevel, cxGridCustomTableView,
  cxGridDBTableView, cxGridCustomView, cxGrid, cxDropDownEdit, cxCalc,
  cxDBEdit, cxSpinEdit, cxLabel, cxTextEdit, cxMaskEdit, cxLookupEdit,
  cxDBLookupEdit, cxDBLookupComboBox, cxGridBandedTableView,
  cxGridDBBandedTableView, IBQuery,DateUtils, cxIntlBase, cxintl,
  ppParameter, ppBands, ppCtrls, jpeg, ppPrnabl, ppClass, ppCache, ppProd,
  ppReport, ppEndUsr, ppDB, ppComm, ppRelatv, ppDBPipe, ppStrtch, ppSubRpt,
  cxLookAndFeelPainters, dxSkinsCore, dxSkinBlack, dxSkinBlue,
  dxSkinCaramel, dxSkinCoffee, dxSkinDarkRoom, dxSkinDarkSide, dxSkinFoggy,
  dxSkinGlassOceans, dxSkiniMaginary, dxSkinLilian, dxSkinLiquidSky,
  dxSkinLondonLiquidSky, dxSkinMcSkin, dxSkinMoneyTwins,
  dxSkinOffice2007Black, dxSkinOffice2007Blue, dxSkinOffice2007Green,
  dxSkinOffice2007Pink, dxSkinOffice2007Silver, dxSkinOffice2010Black,
  dxSkinOffice2010Blue, dxSkinOffice2010Silver, dxSkinPumpkin, dxSkinSeven,
  dxSkinSharp, dxSkinSilver, dxSkinSpringTime, dxSkinStardust,
  dxSkinSummer2008, dxSkinsDefaultPainters, dxSkinValentine,
  dxSkinXmas2008Blue, dxSkinscxPCPainter, dxSkinsdxBarPainter, dxPSGlbl,
  dxPSUtl, dxPSEngn, dxPrnPg, dxBkgnd, dxWrap, dxPrnDev, dxPSCompsProvider,
  dxPSFillPatterns, dxPSEdgePatterns, dxPSPDFExportCore, dxPSPDFExport,
  cxDrawTextUtils, dxPSPrVwStd, dxPSPrVwAdv, dxPSPrVwRibbon,
  dxPScxEditorProducers, dxPScxExtEditorProducers,
  dxPScxPageControlProducer, dxBarSkinnedCustForm, dxSkinsdxRibbonPainter,
  dxPSCore, dxPScxCommon, dxPScxGrid6Lnk;

type
  TfrmConsultaDAPPec = class(TfrmConsultaPadrao)
    Panel3: TPanel;
    cbPropriedade: TcxDBLookupComboBox;
    cxLabel6: TcxLabel;
    cxLabel1: TcxLabel;
    cxDBSpinEdit1: TcxDBSpinEdit;
    Panel4: TPanel;
    cxStyle15: TcxStyle;
    cbProdutor: TcxDBLookupComboBox;
    cxLabel2: TcxLabel;
    dsProdutor: TDataSource;
    lstProdutores: TIBQuery;
    lstProdutoresCODIGO: TIntegerField;
    lstProdutoresNOME: TIBStringField;
    lstPropriedade: TIBQuery;
    lstPropriedadeCODIGO: TIntegerField;
    lstPropriedadeNOME: TIBStringField;
    dsPropriedade: TDataSource;
    mtbFiltroPRODUTOR: TIntegerField;
    mtbFiltroPROPRIEDADE: TIntegerField;
    mtbFiltroANO_BASE: TIntegerField;
    btnConfigura: TdxBarButton;
    ActConfigura: TAction;
    edtRel: TIBDataSet;
    edtRelCODIGO: TIntegerField;
    edtRelCODIGO2: TIBStringField;
    dtEditRel: TDataSource;
    ppRel: TppDBPipeline;
    ppLayoutRel: TppDBPipeline;
    Designer_Rel: TppDesigner;
    rptRel: TppReport;
    ppParameterList1: TppParameterList;
    ActImprimir: TAction;
    ActConfigRel: TAction;
    btnConfigRel: TdxBarButton;
    lstParametro: TIBQuery;
    lstParametroCODIGO: TIntegerField;
    lstParametroUSUARIO: TIntegerField;
    lstParametroDATA_MOVTO: TDateField;
    lstParametroOPERACAO: TIntegerField;
    lstParametroPRODUTOR: TIntegerField;
    lstParametroTERCEIRO: TIntegerField;
    lstParametroPROPRIEDADE: TIntegerField;
    lstParametroPRODUTO: TIntegerField;
    lstParametroANO_BASE: TIntegerField;
    ppTitleBand6: TppTitleBand;
    ppShape22: TppShape;
    ppLabel1: TppLabel;
    ppLabel24: TppLabel;
    ppLabel25: TppLabel;
    ppLabel26: TppLabel;
    ppLabel27: TppLabel;
    ppHeaderBand1: TppHeaderBand;
    ppShape1: TppShape;
    ppShape3: TppShape;
    ppLabel2: TppLabel;
    ppLabel4: TppLabel;
    ppShape4: TppShape;
    ppLabel5: TppLabel;
    ppLabel6: TppLabel;
    ppLabel7: TppLabel;
    ppLine1: TppLine;
    ppLine2: TppLine;
    ppLine3: TppLine;
    ppLine4: TppLine;
    ppLine5: TppLine;
    ppLine6: TppLine;
    ppLabel11: TppLabel;
    ppLine7: TppLine;
    ppLine8: TppLine;
    ppLabel12: TppLabel;
    ppLabel13: TppLabel;
    ppLine9: TppLine;
    ppLabel14: TppLabel;
    ppLabel15: TppLabel;
    ppLabel16: TppLabel;
    ppLabel17: TppLabel;
    ppLabel18: TppLabel;
    ppLine10: TppLine;
    ppLine11: TppLine;
    ppLine12: TppLine;
    ppLine13: TppLine;
    ppDetailBand30: TppDetailBand;
    ppShape15: TppShape;
    ppShape14: TppShape;
    ppShape13: TppShape;
    ppShape7: TppShape;
    ppShape5: TppShape;
    ppShape6: TppShape;
    ppShape8: TppShape;
    ppShape9: TppShape;
    ppShape10: TppShape;
    ppShape11: TppShape;
    ppShape12: TppShape;
    ppShape16: TppShape;
    ppShape17: TppShape;
    ppShape18: TppShape;
    ppFooterBand5: TppFooterBand;
    ppSummaryBand2: TppSummaryBand;
    pgcMovimento: TcxPageControl;
    dtEditINICIAL: TIBBCDField;
    dtEditE_NAC: TIBBCDField;
    dtEditE_INTERNA: TIBBCDField;
    dtEditE_EXT_EXP: TIBBCDField;
    dtEditE_TRF: TIBBCDField;
    dtEditE_ARR_PRC: TIBBCDField;
    dtEditE_HER_DOA: TIBBCDField;
    dtEditE_LEILAO: TIBBCDField;
    dtEditE_ERA: TIBBCDField;
    dtEditS_MORTE: TIBBCDField;
    dtEditS_INTERNA: TIBBCDField;
    dtEditS_EXT_EXP: TIBBCDField;
    dtEditS_TRF: TIBBCDField;
    dtEditS_ARR_PRC: TIBBCDField;
    dtEditS_HER_DOA: TIBBCDField;
    dtEditS_LEILAO: TIBBCDField;
    dtEditS_ERA: TIBBCDField;
    dtEditFINAL: TIBBCDField;
    Grid: TcxGrid;
    GridDBBandedTableView1: TcxGridDBBandedTableView;
    GridDBBandedTableView1INICIAL: TcxGridDBBandedColumn;
    GridDBBandedTableView1E_NAC: TcxGridDBBandedColumn;
    GridDBBandedTableView1E_INTERNA: TcxGridDBBandedColumn;
    GridDBBandedTableView1E_EXT_EXP: TcxGridDBBandedColumn;
    GridDBBandedTableView1E_TRF: TcxGridDBBandedColumn;
    GridDBBandedTableView1E_ARR_PRC: TcxGridDBBandedColumn;
    GridDBBandedTableView1E_HER_DOA: TcxGridDBBandedColumn;
    GridDBBandedTableView1E_LEILAO: TcxGridDBBandedColumn;
    GridDBBandedTableView1E_ERA: TcxGridDBBandedColumn;
    GridDBBandedTableView1S_MORTE: TcxGridDBBandedColumn;
    GridDBBandedTableView1S_INTERNA: TcxGridDBBandedColumn;
    GridDBBandedTableView1S_EXT_EXP: TcxGridDBBandedColumn;
    GridDBBandedTableView1S_TRF: TcxGridDBBandedColumn;
    GridDBBandedTableView1S_ARR_PRC: TcxGridDBBandedColumn;
    GridDBBandedTableView1S_HER_DOA: TcxGridDBBandedColumn;
    GridDBBandedTableView1S_LEILAO: TcxGridDBBandedColumn;
    GridDBBandedTableView1S_ERA: TcxGridDBBandedColumn;
    GridDBBandedTableView1FINAL: TcxGridDBBandedColumn;
    GridLevel1: TcxGridLevel;
    edtRelDAP_PECUARIA: TMemoField;
    dtEditDESCRICAO: TIBStringField;
    GridDBBandedTableView1DESCRICAO: TcxGridDBBandedColumn;
    dtEditDESC_DAP_PEC: TIBStringField;
    GridDBBandedTableView1DESC_DAP_PEC: TcxGridDBBandedColumn;
    impressora: TdxComponentPrinter;
    impressoraLink1: TdxGridReportLink;
    procedure FormShow(Sender: TObject);
    procedure lstPropriedadeBeforeOpen(DataSet: TDataSet);
    procedure ActFilterExecute(Sender: TObject);
    procedure GridEnter(Sender: TObject);
    procedure mtbFiltroPRODUTORValidate(Sender: TField);
    procedure ActConfiguraExecute(Sender: TObject);
    procedure ActConfigRelExecute(Sender: TObject);
    procedure ActImprimirExecute(Sender: TObject);
    procedure lstParametroBeforeOpen(DataSet: TDataSet);
  private
    { Private declarations }
    procedure abreconsultas;
  public
    { Public declarations }
  end;

var
  frmConsultaDAPPec: TfrmConsultaDAPPec;

implementation

uses untDmPrincipal;

{$R *.dfm}

procedure TfrmConsultaDAPPec.FormShow(Sender: TObject);
begin
  inherited;
  lstProdutores.Close;
  lstProdutores.Open;

  abreconsultas;

  cbProdutor.SetFocus;

  lstParametro.Close;
  lstParametro.Open;


  if lstParametroANO_BASE.AsInteger > 0 then
    mtbFiltroANO_BASE.Value := lstParametroANO_BASE.AsInteger
  else
    mtbFiltroANO_BASE.Value :=  YearOf(date);

end;

procedure TfrmConsultaDAPPec.lstPropriedadeBeforeOpen(DataSet: TDataSet);
begin
  inherited;
  TIBQuery(DataSet).ParamByName('codigo').value := mtbFiltroPRODUTOR.AsInteger;
   TIBQuery(DataSet).ParamByName('ano').value := mtbFiltroANO_BASE.AsInteger;
end;

procedure TfrmConsultaDAPPec.ActFilterExecute(Sender: TObject);
begin
  inherited;
  Grid.SetFocus;
  dtEdit.Close;
  dtEdit.ParamByName('propriedade').value := mtbFiltroPROPRIEDADE.AsInteger;
  dtEdit.ParamByName('ano_base').value := mtbFiltroANO_BASE.AsInteger;
  dtEdit.Open;
end;

procedure TfrmConsultaDAPPec.GridEnter(Sender: TObject);
begin
  inherited;
  ActFilter.Execute;
end;

procedure TfrmConsultaDAPPec.abreconsultas;
begin
  lstPropriedade.Close;
  lstPropriedade.Open;
end;

procedure TfrmConsultaDAPPec.mtbFiltroPRODUTORValidate(Sender: TField);
begin
  inherited;
  abreconsultas;
end;

procedure TfrmConsultaDAPPec.ActConfiguraExecute(Sender: TObject);
begin
  inherited;
  TcxGridTableController(Grid.FocusedView.Controller).Customization := True;
end;

procedure TfrmConsultaDAPPec.ActConfigRelExecute(Sender: TObject);
begin
  inherited;
  edtRel.close;
  edtRel.parambyname('codigo').value := 1;
  edtRel.Open;

  rptRel.Template.DatabaseSettings.Name := edtRelCODIGO2.asstring;
  rptRel.Template.LoadFromDatabase;
  Designer_Rel.Show;
  edtRel.edit;

  edtRel.Transaction.CommitRetaining;
end;

procedure TfrmConsultaDAPPec.ActImprimirExecute(Sender: TObject);
begin
  inherited;
  impressora.Preview();
  edtRel.close;
  edtRel.parambyname('codigo').value := 1;
  edtRel.Open;

  rptRel.Template.DatabaseSettings.Name := edtRelCODIGO2.asstring;
  rptRel.Template.LoadFromDatabase;

  rptRel.print;
end;

procedure TfrmConsultaDAPPec.lstParametroBeforeOpen(DataSet: TDataSet);
begin
  inherited;
  lstParametro.ParamByName('usuario').value := dmPrincipal.usuario_logado_codigo;
end;

end.
